home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
Pete Johnson
/
mehit 3.0.b15<source>.cpt
/
FileAndStuffIt.p
< prev
next >
Wrap
Text File
|
1991-07-25
|
11KB
|
379 lines
unit FileAndStuffIt;
interface
uses
Globals, HelloTabby, mehitFile, LogUtils;
type
FileSpecPtr = ^FileSpec;
FileSpec = record
v: Integer;{ volume refNum}
d: Longint;{ directory id}
n: string[31];{ file/folder name}
method: signedbyte;{ comp method - used in compression only}
deleteIt: boolean;{ delete original file/folder when done?}
end;
FileListHdl = ^FileListPtr;
FileListPtr = ^FileListRec;
FileListRec = record
count: integer;{ # of files/folders below}
ary: array[0..0] of filespec;{ array of files to act on}
end;
var
StuffRef: integer;
StuffResource: handle;
savePort: GrafPtr;
StuffItMode: integer;
modeString, StuffItVersion: str255;
StuffItExists: boolean;
procedure myCloseWD;
function GetDirInfo (ourPath: str255; var ourVRef: integer): OSErr;
function GetFileName (Input: str255): str255;
function GetPath (Input: str255): str255;
function DoStuff (theFiles: FileListHdl; { list of files to compress}
destFile: FileSpecPtr; { result file name/location}
title: Str255; { title of progress windows}
Addr: Ptr): OSErr; { address to jump to (start of the resource)}
function FindStuffIt: boolean;
procedure CloseStuffIt;
procedure StuffMessages;
procedure StuffOne (fName: str255; StuffMode: StuffOpts; deleteFile: boolean);
implementation
{----------------------------------------------------------------- }
function GetDirInfo;{(ourPath: str255; var ourVRef: integer): OSErr}
var
i: integer;
ourDirRef: longint;
myWDPBRec: WDPBRec;
Error: OSErr;
tempString: str255;
begin
while (ourPath[length(ourPath)] <> ':') & (length(ourPath) > 1) do
ourPath := copy(ourPath, 1, length(ourPath) - 1);
tempString := ourPath; {make an extra copy since HGetVol truncates the string}
Error := HGetVol(@tempString, ourVRef, ourDirRef);
with myWDPBRec do
begin
ioNamePtr := @ourPath;
ioVRefNum := ourVRef;
ioWDDirID := ourDirRef;
ioWDProcID := MySignature;
Error := PBOpenWD(@myWDPBRec, false);
if ioVRefNum <> DefaultVol then {StuffIt doesn't like being fed a working }
ourVRef := ioVRefNum {directory when file is in default directory }
end;
GetDirInfo := Error
end;
{----------------------------------------------------------------- }
procedure myCloseWD;
var
counter: integer;
myWDPBRec: WDPBRec;
begin
counter := 0;
repeat
counter := succ(counter);
with myWDPBRec do
begin
ioCompletion := nil;
ioWDProcID := mySignature;
ioWDIndex := counter;
ioVRefNum := 0;
end;
Err := PBGetWDInfo(@myWDPBRec, false);
if Err = noErr then
Err := PBCloseWD(@myWDPBRec, false);
until Err <> noErr
end;
{----------------------------------------------------------------- }
function GetFileName;{(Input: str255): str255}
begin
while (pos(':', Input) > 0) & (length(Input) > 1) do
Input := copy(Input, pos(':', Input) + 1, 255);
GetFileName := Input
end;
{ ------------------------------------------------------ }
function GetPath;{ (Input: str255): str255}
begin
while not (Input[length(Input)] in [':']) & (length(Input) > 1) do
Input := copy(Input, 1, length(Input) - 1);
if length(Input) = 1 then
Input := ':';
GetPath := Input
end;
{ ------------------------------------------------------ }
function Stuff (theFiles: FileListHdl; { list of files to compress}
destFile: FileSpecPtr; { result file name/location}
title: Str255; { title of progress windows}
Addr: Ptr): OSErr; { address to jump to (start of the resource)}
inline
$205F, $4E90; { pop last param & jump to it}
{----------------------------------------------------------------- }
function DoStuff;
{ (theFiles: FileListHdl; list of files to compress}
{ destFile: FileSpecPtr; result file name/location}
{ title: Str255; title of progress windows}
{ Addr: Ptr): OSErr; address to jump to (start of the resource)}
begin
Err := Stuff(theFiles, destFile, title, Addr)
end;
{----------------------------------------------------------------- }
function FindStuffIt;{: boolean}
var
error: OSErr;
theWorld: SysEnvRec;
StuffVRef: integer;
SystemPath: str255;
begin
StuffResource := nil;
error := SysEnvirons(1, theWorld);
StuffVRef := theWorld.sysVRefNum; {it's in the System Folder}
MakePath('System', StuffVRef, SystemPath);
if error = noErr then
StuffRef := OpenResFile(concat(SystemPath, 'Extensions:StuffIt Engine™'));
if (StuffRef <> -1) then
begin
StuffResource := Get1IndResource('MENC', 1);
GetPort(savePort); { Only needed when calling v1.0 of the engine}
end;
if (error = noErr) & (StuffRef <> -1) then
begin
FindStuffIt := true;
StuffItExists := true;
StuffItVersion := ReadVersion
end
else
FindStuffIt := false
end;
{----------------------------------------------------------------- }
procedure CloseStuffIt;
begin
if StuffResource <> nil then
begin
ReleaseResource(StuffResource);
CloseResFile(StuffRef);
StuffResource := nil;
end
end;
{----------------------------------------------------------------- }
procedure StuffMessages;
var
destFile: FileSpec;
StuffFilesHandle: FileListHdl;
i, backupVol, MESSAGESVol, MFilesVol, ULVol: integer;
aString, introString: str255;
beginStuffTime, endStuffTime, StuffTime: longint;
stuffMin, stuffSec: integer;
StuffErr: OSErr;
begin
StuffFilesHandle := nil;
if FindStuffIt & (DefaultsPtr^.DBackupMode in [StuffNone..StuffBetter]) then
begin
if DefaultsPtr^.WriteToTabby then
begin
TimeStamp;
Err := FSOpen(concat(gDefaultpath, 'Tabby:Tabby Log'), DefaultVol, TLogRef);
Err := SetFPos(TLogRef, fsFromLEOF, 0);
Err := WrLn(TLogRef, concat(DateString, ' mehitabel - stuffing with engine ', StuffItVersion, ' using ''', modeString, ''' mode'));
end;
GetDateTime(beginStuffTime);
StuffItMode := ord(DefaultsPtr^.DBackupMode) - 3;
Err := GetDirInfo(concat(DefaultsPtr^.DBackupPath, 'Messages.sit'), backupVol);
Err := GetDirInfo(MESSAGESPath, MESSAGESVol);
Err := GetDirInfo(MsgPath, MFilesVol);
Err := GetDirInfo(ULPath, ULVol);
Err := FSDelete(concat(DefaultsPtr^.DBackupPath, 'Messages.sit'), backupVol);
with destFile do
begin
v := BackupVol;
d := 0;
n := concat(DefaultsPtr^.DBackupPath, 'Messages.sit');
method := StuffItMode;
deleteIt := false;
end;
StuffFilesHandle := FileListHdl(NewHandle((sizeOf(FileListHdl)) + (4 * sizeOf(filespec))));
MoveHHi(Handle(StuffFilesHandle));
HLock(Handle(StuffFilesHandle));
with StuffFilesHandle^^ do
begin
count := 4;
with ary[0] do
begin
v := MESSAGESVol;
d := 0;
n := 'MESSAGES';
method := StuffItMode;
deleteIt := false
end;
with ary[1] do
begin
v := MFilesVol;
d := 0;
n := 'MSGHDR';
method := StuffItMode;
deleteIt := false
end;
with ary[2] do
begin
v := MFilesVol;
d := 0;
n := 'MSGTXT';
method := StuffItMode;
deleteIt := false
end;
with ary[3] do
begin
v := ULVol;
d := 0;
n := 'UserLog';
method := StuffItMode;
deleteIt := false
end;
end;
MoveHHi(StuffResource);
HLock(StuffResource);
StuffErr := Stuff(StuffFilesHandle, @destFile, 'shrinking backups', StuffResource^);
HUnlock(StuffResource);
HUnlock(Handle(StuffFilesHandle));
if StuffFilesHandle <> nil then
begin
DisposHandle(Handle(StuffFilesHandle));
StuffFilesHandle := nil;
end;
CloseStuffIt;
SetPort(savePort); { Only needed when calling v1.0 of the engine}
if DefaultsPtr^.WriteToTabby then
begin
TimeStamp;
introString := concat(DateString, ' mehitabel - ');
if StuffErr = noErr then
begin
GetDateTime(endStuffTime);
StuffTime := endStuffTime - beginStuffTime;
stuffMin := StuffTime div 60;
stuffSec := StuffTime mod 60;
aString := StringOf(stuffSec : 1);
while length(aString) < 2 do
aString := concat('0', aString);
aString := concat(introString, 'stuffing time ', StringOf(stuffMin : 1), ':', aString, ' free memory: ', stringOf(freeMem div 1024 : 1), 'K')
end
else if StuffErr = -1 then
aString := concat(introString, 'stuffit cancelled')
else
aString := concat(introString, 'stuffit error ', stringOf(StuffErr : 1));
Err := WrLn(TLogRef, aString);
Err := FSClose(TLogRef);
end;
end;{if FindStuffIt & (DefaultsPtr^.DBackupMode in [StuffNone..StuffBetter])}
if err <> noErr then
err := noErr;
SetCursor(GetCursor(1000)^^)
end;
{----------------------------------------------------------------- }
procedure StuffOne;{(fName: str255; StuffMode: StuffOpts; deleteFile: boolean)}
var
destFile: FileSpec;
StuffFilesHandle: FileListHdl;
i, backupVol, sourceVol: integer;
aString, introString, tempName: str255;
StuffErr: OSErr;
begin
StuffFilesHandle := nil;
if FindStuffIt then
begin
Err := GetDirInfo(concat(fName), sourceVol);
tempName := concat(GetFileName(fName), '.sit');
Err := GetDirInfo(concat(DefaultsPtr^.DBackupPath, tempName), backupVol);
Err := FSDelete(concat(DefaultsPtr^.DBackupPath, tempName), backupVol);
with destFile do
begin
v := BackupVol;
d := 0;
n := tempName;
method := ord(StuffMode);
deleteIt := false;
end;
StuffFilesHandle := FileListHdl(NewHandle((sizeOf(FileListHdl)) + (1 * sizeOf(filespec))));
MoveHHi(Handle(StuffFilesHandle));
HLock(Handle(StuffFilesHandle));
with StuffFilesHandle^^ do
begin
count := 1;
with ary[0] do
begin
v := sourceVol;
d := 0;
n := GetFileName(fName);
method := ord(StuffMode);
deleteIt := deleteFile
end;
end;
MoveHHi(StuffResource);
HLock(StuffResource);
StuffErr := Stuff(StuffFilesHandle, @destFile, 'shrinking log', StuffResource^);
HUnlock(StuffResource);
HUnlock(Handle(StuffFilesHandle));
if StuffFilesHandle <> nil then
begin
DisposHandle(Handle(StuffFilesHandle));
StuffFilesHandle := nil;
end;
CloseStuffIt;
SetPort(savePort) { Only needed when calling v1.0 of the engine}
end;
SetCursor(GetCursor(1000)^^)
end;
{----------------------------------------------------------------- }
end.